package algotithm.weekendrace.leetcode232.test1;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/14-14:58
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        String s1 = "kelb";
        String s2 = "kelb";
        boolean b = solution.areAlmostEqual(s1, s2);
        System.out.println(b);
    }

    public boolean areAlmostEqual(String s1, String s2) {
        if (s1.equals(s2)) {
            return true;
        }
        int[] count1 = new int[26];
        int[] count2 = new int[26];
        int length = s1.length();
        int different = 0;
        for (int i = 0; i < length; i++) {
            char c1 = s1.charAt(i), c2 = s2.charAt(i);
            if (c1 != c2) {
                different++;
            }
            count1[c1 - 'a']++;
            count2[c2 - 'a']++;
        }
        if (different != 2) {
            return false;
        }
        for (int i = 0; i < 26; i++) {
            if (count1[i] != count2[i]) {
                return false;
            }
        }
        return true;
    }
}
